package com.imooc.poker_game;

import com.imooc.poker_game.exception.WrongCommandException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Player {
    /**
     * 玩家姓名
     */
    String name;
    /**
     * ID
     */
    String id;

    /**
     * 手里的牌 - 两张
     */
    List<PokerPiece> pokerPieces;

    public Player() {

    }

    public Player(String id, String name) throws WrongCommandException {
        try {
            Integer.parseInt(id);
            this.id = id;
            this.name = name;
            pokerPieces = new ArrayList<PokerPiece>();
        } catch (NumberFormatException e) {
            throw new WrongCommandException("player id should be numerical. s");
        }

    }

    /**
     * 获取一张牌
     * @param pokerPiece PokerPiece
     */
    public void addPiece(PokerPiece pokerPiece) {
//        System.out.println("花色：" + pokerPiece.pattern + " 面值：" + pokerPiece.figure);
        pokerPieces.add(pokerPiece);
    }

    /**
     * 获取最好的一张牌
     * @return
     */
    public PokerPiece bestPiece() {
        Collections.sort(this.pokerPieces);
        return this.pokerPieces.get(0);
    }

    /**
     * 展示手上的牌
     * @return
     */
    public String show() {
        List<String> pieces_str = new ArrayList<String>();
        for (PokerPiece piece:this.pokerPieces) {
            pieces_str.add(piece.show());
        }
        return pieces_str.toString();
    }
}
